package com.controll.jaxb;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import com.bean.jaxb.user.UserVo;

public class parseXml2Bean {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {  
//			InputStream is = new FileInputStream( "data/userInfo.xml" );
			JAXBContext jaxbContext = JAXBContext.newInstance(UserVo.class);  
			Unmarshaller um = jaxbContext.createUnmarshaller();  
			UserVo user = new UserVo();
			user = (UserVo)um.unmarshal(new File("data/userInfo.xml"));  
			System.out.println(user);
			
			Marshaller m = jaxbContext.createMarshaller();
			m.setProperty(Marshaller.JAXB_ENCODING, "MS950");
			m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
			m.marshal(user, new File("data/userInfo.xml"));
			m.marshal(user, System.out);
			
		}catch (JAXBException e) {  
			e.printStackTrace();
        } catch (Exception e) {			
			e.printStackTrace();
		}  
	}

}
